<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>会籍顾问 - 工作记录</title>
<link draggable="true" rel="stylesheet" href="${viewPath}/resources/css/statistics.css" />
$!{include("import_js_css.html")} $!{include("header.html")}
<script type="text/javascript">
function documentReady(){
	initTable();
	$("#keeperId").select2({
		width:"100%"
	});
	$("#inputStartDate1").datetimepicker({
		language : "zh-CN"
	});
	$("#inputStartDate2").datetimepicker({
		language : "zh-CN"
	});
	$("#btn_search").click(function(){
		initTable();
	});
}
var t1 = "";
var t4 = "";
function initTable(){
	$("#stat_list table thead").remove();
	$("#stat_list table tbody").remove();
	var fromDate = $("#inputStart1").val();
	var toDate = $("#inputStart2").val();
	var keeperId = $("#keeperId").val();
	var url = "${basePath}/yueyogaAdmin/keeperRecordQuery.jhtml";
	$.post(url,
		{fromDate:fromDate,toDate:toDate,keeperId:keeperId},
		function(resp){
			if(!resp){	
				$("#stat_list table").append(t1);
				$("#stat_list table").append(t4);
				return;
			}
			var data = eval("("+resp+")");
			var headerTrs = data.header;
			var bodyTrs = data.body;
			var len = headerTrs.length + bodyTrs.length - 1 ;
			var tb = "<thead>";
			var tb1 = "<thead>";
			$.each(headerTrs, function(tr, htr) { 
				var htds = htr.tds;
				tb +="<tr>";
				tb1+="<tr>";
				$.each(htds,function(td,htd){
					tb +="<th style='text-align:center;' colspan='"+htd.colspan+"' rowspan='"+htd.rowspan+"' data='"+htd.id+"'>" + htd.text + "</th>";
					tb1 +="<th style='text-align:center;' colspan='"+htd.colspan+"' rowspan='"+htd.rowspan+"' data='"+htd.id+"'>" + htd.text + "</th>";
				});
				tb +="</tr>";
				tb1+="</tr>";
			}); 
			tb +="</thead>";
			tb1 +="</thead>";
			t1 = tb1;
			$("#stat_list table").append(tb);
			
			//--tbody
			tb = "<tbody>";
			$.each(bodyTrs, function(tr, btr) { 
				var btds = btr.tds;
				tb +="<tr>";
				$.each(btds,function(td,btd){
					if(btd.text=='小计'){
						tb +="<td id='xj_total' colspan='"+btd.colspan+"' rowspan='"+btd.rowspan+"' data='"+btd.id+"'>" + btd.text + "</td>";
					}else if(btd.text=='总计'){
						tb +="<td id='zj_total' colspan='"+btd.colspan+"' rowspan='"+btd.rowspan+"' data='"+btd.id+"'>" + btd.text + "</td>";
					}else{
						tb +="<td colspan='"+btd.colspan+"' rowspan='"+btd.rowspan+"' data='"+btd.id+"'>" + btd.text + "</td>";
					}
				});
				tb +="</tr>";
			});
			tb +="</tbody>";
			$("#stat_list table").append(tb);
			var xjtr =  $("#xj_total").parent();
			var len = xjtr.children().length;
			var child = xjtr.children();
			var str = "<tr>";
			var str1 = "<tr>";
			for(var i=0;i<len;i++){
				str +="<td>" +child.eq(i).text()+ "</td>";
			}
			str +="</tr>";
			$(xjtr).remove();
			$("#stat_list table").append(str);
			var zjtr = $("#zj_total").parent();
			var total = $("#zj_total").next().text();
			$("#zj_total").parent().remove();
			var tstr = "<tr><td>总计</td><td colspan='"+(len-1)+"'>"+total+"</td></tr>";
			var tstr1 = "<tr><td>总计</td><td colspan='"+(len-1)+"'>-</td></tr>";
			t4 = tstr1;
			$("#stat_list table").append(tstr);
	});
}
</script>
</head>
<body style="background-color: #fff;">
	<div id="drag_container" class="container menu_all">
		<div class="row-fluid panel-radius-stat span12">
			<div id="stat_kpr_cdts">
				<div class="stat-kpr-hall">会馆:${hallName}</div>
				<div class="stat-kpr-date">
					<div style="float:left; margin-right:5px;margin-top:5px;">日期</div>
					<div id="inputStartDate1" class="input-group date"
						data-date-format="YYYY-MM-DD" style="float:left; width:200px;">
						<input id="inputStart1" name="startdate" type='text' class="form-control" value="${startdate}" />
						<span class="input-group-addon">
							<span class="glyphicon glyphicon-time"></span>
						</span>
					</div>
					<div style="float:left; margin-left:5px; margin-right:5px;margin-top:5px;">至</div>
					<div id="inputStartDate2" class="input-group date"
						data-date-format="YYYY-MM-DD" style="float:left; width:200px;">
						<input id="inputStart2" name="enddate" type='text' class="form-control" value="${enddate}" />
						<span class="input-group-addon">
							<span class="glyphicon glyphicon-time"></span>
						</span>
					</div>
					<div class="stat-kpr-sel">
				<!-- #set(List<GroupUserModel> keepers) -->
				<select id="keeperId">
					<option value="">全部</option>
					<!-- #for(GroupUserModel keeper:keepers) -->
					<option value="${keeper.id}">${keeper.name} </option>
					<!-- #end -->
				</select></div>
				</div>
				<div style="float:left;margin-top:5px;margin-left:-90px;">
						<input id="btn_search" type="button" class="btn btn-ade-default" value="搜索"></input>
					</div>
			</div>
	</div>
			<div id="stat_list" class="panel panel-default clear">
				<table class="table table-bordered table-hover table-condensed">

				</table>
			</div>
		</div>
</body>
</html>